Use :dnd pseudoclass for drag highlighting
authorMatthias Clasen <mclasen@redhat.com>
Thu, 3 Dec 2015 04:49:07 +0000 (23:49 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 3 Dec 2015 04:49:07 +0000 (23:49 -0500)
Instead of a ::draw handler with a hardcoded outline,
use CSS for drawing the highlight.

gtk/gtkdnd.c
gtk/theme/Adwaita/_common.scss
gtk/theme/Adwaita/gtk-contained-dark.css
gtk/theme/Adwaita/gtk-contained.css

index fb6c1ab35bd819ff284085bb418213f8519e2f02..52023afdf5073d7df7c0b4733d72d6a77650333f 100644 (file)
@@ -983,48 +983,6 @@ gtk_drag_finish (GdkDragContext *context,
     gdk_drop_finish (context, success, time);
 }
 
-static gboolean
-gtk_drag_highlight_draw (GtkWidget *widget,
-                         cairo_t   *cr,
-                         gpointer   data)
-{
-  GtkAllocation alloc;
-  GtkStyleContext *context;
-
-  if (GTK_IS_WINDOW (widget))
-    {
-      /* We don't want to draw the drag highlight around the
-       * CSD window decorations
-       */
-      gtk_widget_get_allocation (gtk_bin_get_child (GTK_BIN (widget)), &alloc);
-    }
-  else
-    {
-      alloc.x = 0;
-      alloc.y = 0;
-      alloc.width = gtk_widget_get_allocated_width (widget);
-      alloc.height = gtk_widget_get_allocated_height (widget);
-    }
-
-  context = gtk_widget_get_style_context (widget);
-
-  gtk_style_context_save (context);
-  gtk_style_context_add_class (context, GTK_STYLE_CLASS_DND);
-
-  gtk_render_frame (context, cr, alloc.x, alloc.y, alloc.width, alloc.height);
-
-  gtk_style_context_restore (context);
-
-  cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
-  cairo_set_line_width (cr, 1.0);
-  cairo_rectangle (cr,
-                   alloc.x + 0.5, alloc.y + 0.5,
-                   alloc.width - 1, alloc.height - 1);
-  cairo_stroke (cr);
-
-  return FALSE;
-}
-
 /**
  * gtk_drag_highlight: (method)
  * @widget: a widget to highlight
@@ -1034,16 +992,12 @@ gtk_drag_highlight_draw (GtkWidget *widget,
  * will continue to be displayed until gtk_drag_unhighlight()
  * is called.
  */
-void 
+void
 gtk_drag_highlight (GtkWidget  *widget)
 {
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
-  g_signal_connect_after (widget, "draw",
-                          G_CALLBACK (gtk_drag_highlight_draw),
-                          NULL);
-
-  gtk_widget_queue_draw (widget);
+  gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_DND, FALSE);
 }
 
 /**
@@ -1053,16 +1007,12 @@ gtk_drag_highlight (GtkWidget  *widget)
  * Removes a highlight set by gtk_drag_highlight() from
  * a widget.
  */
-void 
+void
 gtk_drag_unhighlight (GtkWidget *widget)
 {
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
-  g_signal_handlers_disconnect_by_func (widget,
-                                        gtk_drag_highlight_draw,
-                                        NULL);
-  
-  gtk_widget_queue_draw (widget);
+  gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_DND);
 }
 
 static void
index 7fef5610bf2f321b7bf77b9760ca05959d4aaf83..00491417504b22363534de15a5db54acb6966883 100644 (file)
@@ -3438,3 +3438,7 @@ frame.keycap {
   padding: 3px 8px 3px 8px;
 }
 
+*:dnd:focus,
+*:dnd {
+  border: 1px solid black;
+}
index 3d4d4dfec93732d6946c7051dcd9d66cd5bf19f7..a3b1cf4d3dce64520fdb2db252ed5d8585e61fde 100644 (file)
@@ -4665,6 +4665,10 @@ frame.keycap {
   color: #555753;
   padding: 3px 8px 3px 8px; }
 
+*:dnd:focus,
+*:dnd {
+  border: 1px solid black; }
+
 /* GTK NAMED COLORS
    ----------------
    use responsibly! */
index 77c1b67a86cc4de72686b79fc96bcfa4607d4d61..cac2b0e044cd148958c0245785340d555c65a5d3 100644 (file)
@@ -4838,6 +4838,10 @@ frame.keycap {
   color: #555753;
   padding: 3px 8px 3px 8px; }
 
+*:dnd:focus,
+*:dnd {
+  border: 1px solid black; }
+
 /* GTK NAMED COLORS
    ----------------
    use responsibly! */